
ALTER PROCEDURE [dbo].[GetTodayMatche]    
 -- Add the parameters for the stored procedure here    
 @MatchType INT
     
AS    
BEGIN    
 -- SET NOCOUNT ON added to prevent extra result sets from    
 -- interfering with SELECT statements.    
 SET NOCOUNT ON;    
    
    -- Insert statements for procedure here    
    SELECT ms.Id as Id, t.TeamName as Team1 ,t1.TeamName as Team2, (t.TeamName + ' VS ' + t1.TeamName) as Teams,Date, Time,  
    t.Id as TeamAId, t1.Id as TeamBId   
    from MatchSchedule ms    
     INNER JOIN Team t on ms.Team1 = t.Id    
 INNER JOIN Team t1 on ms.Team2 = t1.Id    
 WHERE CAST(ms.Date as DATE) = CAST(GETUTCDATE() as DATE) and ms.IsActive = 1 and ms.IsDeleted = 0   
 and ms.MatchType = @MatchType 
     
END 




ALTER PROCEDURE [dbo].[GetSessionBettingForClient]    
 -- Add the parameters for the stored procedure here    
 @AdminId INT,
 @MatchId INT,
 @BettingTypeId INT
     
AS    
BEGIN    
 -- SET NOCOUNT ON added to prevent extra result sets from    
 -- interfering with SELECT statements.    
 SET NOCOUNT ON;    
    
    -- Insert statements for procedure here    
    IF EXISTS (
		SELECT Id from Betting where IsDeleted=0
    )
    BEGIN
        PRINT 'New'
		select b.Id,b.CreatedBy,b.LagadiRate,b.KhadhiRate,b.TeamId,b.MatchScheduleId,
		(t.TeamName + ' VS ' + t1.TeamName) as Team,t.TeamName as Team1,t1.TeamName as Team2,
		b.[Over] as [Over]

		from Betting b
		inner join MatchSchedule m on b.MatchScheduleId = m.Id
		inner join Team t on m.Team1 = t.Id
		inner join Team t1 on m.Team2 = t1.Id
		where b.IsDeleted = 0 and b.CreatedBy= @AdminId and b.BettingTypeId = @BettingTypeId and 
		b.MatchScheduleId = @MatchId
     END
     ELSE
     BEGIN
        PRINT 'OLD'
		select top 1 b.Id,b.CreatedBy,b.LagadiRate,b.KhadhiRate,b.TeamId,b.MatchScheduleId,
		(t.TeamName + ' VS ' + t1.TeamName) as Team,t.TeamName as Team1,t1.TeamName as Team2,
		b.[Over] as [Over]

		from Betting b
		inner join MatchSchedule m on b.MatchScheduleId = m.Id
		inner join Team t on m.Team1 = t.Id
		inner join Team t1 on m.Team2 = t1.Id
		where b.CreatedBy= @AdminId and b.BettingTypeId = @BettingTypeId and 
		b.MatchScheduleId = @MatchId and Cast(b.CreatedDate as date) = cast(GETUTCDATE() as date)
		ORDER BY Id desc
     END
END 


